home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-30 | 8.0 KB | 208 lines | [TEXT/MPS ] |
- {[j=20/53/1$] Pasmat Options}
-
- UNIT UOffscreen;
-
- {-------------------------------------------------------------------------------------------
-
- Program: FracApp 2.0
- Unit: UOffscreen
- Files: UOffscreen.p
- Includes: UOffscreen.inc1.p
-
- by Keith Rollin & Bo3b Johnson
- of Apple Macintosh Developer Technical Support
-
- Copyright © 1989-1990 Apple Computer, Inc.
- All rights reserved.
-
- --------------------------------------------------------------------------------------------
-
- Offscreen management. Herein, we have three objects. There is a TOffscreen
- object, that defines some common routines and method names. It really doesn’t
- do a whole lot, as most of the functionality is implemented in its
- sub-classes: TOldGrossOffscreen, and TNewCoolOffscreen.
-
- TOldGrossOffscreen is a set of home brew routines that implement offscreen
- PixMaps totally by hand. These are the routines that are in the original
- version of FracApp. In the past, this was the only way to create offscreen
- PixMaps.When initializing TOldGrossOffscreen, we create a new PixMap and data
- buffer, set up all the values for them, clear the buffer, create a gDevice
- record, initialize it, attach the two together, and hope that it will still
- work under new Systems. TNewCoolOffscreen uses the new 32-Bit Color QuickDraw
- routines if they are available. It just calls NewGWorld, and attaches our color
- table to it.
-
- There are several support routines for TOffscreens. ChangeCTFlag is used to set
- or clear color table flags. This was hacked in to support the need to clear and
- set bit 14 when we save the PixMap to disk. LockThePixels and UnlockThePixels
- is called whenever we have to perform some QuickDraw operation, like CopyBits.
- This is only needed for the TNewCoolOffscreen stuff, and is a null operation
- uner TOldGrossOffscreen. SaveOldWorld and SetupOffWorld are used for saving
- whatever port and gDevice are set, and swapping in the offscreen drawing
- environment. RestoreOffWorld is called when we are done to reverse the effects
- of SetupOffWorld. None of these last 5 routines (LockThePixels,
- UnlockThePixels, SaveOldWorld, SetupOffWorld, RestoreOffWorld) should be called
- directly, as they are combined in the PreDraw and PostDraw routines, which take
- care of all the management. Whenever you need to do offscreen drawing, call
- PreDraw, and then PostDraw when you are done. Finally, if you need to get the
- offscreen port for some direct manipulation (like for CopyBits), call
- GetOffPort.
-
- --------------------------------------------------------------------------------------------}
-
- INTERFACE
-
- USES UMacApp, QDOffScreen;
-
- CONST
-
- kAnimationFlag = 14;
- kClearFlag = FALSE;
- kSetFlag = TRUE;
-
- TYPE
-
- TOffscreen = OBJECT (TObject)
-
- fOldDevice: GDHandle; { Holds the previous device while we’re
- busy playing in the offscreen world.
- You can fetch the device if you need to
- with GetOldDevice. }
- fOldPort: GrafPtr; { Holds the previous GrafPort while we’re
- busy playing in the offscreen world.
- You can fetch the port if you need to
- with GetOldPort. }
- PROCEDURE TOffscreen.IOffscreen;
- { Initialize the offscreen world. }
-
- PROCEDURE TOffscreen.ChangeCTFlag(whichBit: Integer; whichWay: Boolean);
- { Set or clear a color table flag. }
-
- FUNCTION TOffscreen.GetOffDevice: GDHandle;
- { Return the GDHandle of the device belonging to the offscreen port. Must be
- overridden. }
-
- FUNCTION TOffscreen.GetOffPixBase: Ptr;
- { Return the base address of our offscreen pixels. Must be overridden. }
-
- FUNCTION TOffscreen.GetOffPort: CGrafPtr;
- { Return a CGrafPtr to the offscreen port. Must be overridden. }
-
- FUNCTION TOffscreen.GetOldDevice: GDHandle;
- { Return a GDHandle to the saved device. }
-
- FUNCTION TOffscreen.GetOldPort: GrafPtr;
- { Return a GrafPtr to the saved port. }
-
- PROCEDURE TOffscreen.LockThePixels;
- { For 32BCQD support. Does nothing by default. }
-
- PROCEDURE TOffscreen.PreDraw;
- { Call this method to save off the current drawing world and swap in the
- offscreen drawing world. }
-
- PROCEDURE TOffscreen.PostDraw;
- { Call this method to restore the drawing world saved by PreDraw. }
-
- PROCEDURE TOffscreen.RestoreOldWorld;
- { Called by PostDraw to restore the old port and gDevice. Should not need
- to be called directly. PostDraw will call this for you. }
-
- PROCEDURE TOffscreen.SaveOldWorld;
- { Called by PreDraw to save the old port and gDevice. Should not need
- to be called directly. PreDraw will call this for you. }
-
- PROCEDURE TOffscreen.SetupOffWorld;
- { Called by PreDraw to set the offscreen port and gDevice. Must be overridden.
- }
-
- PROCEDURE TOffscreen.UnlockThePixels;
- { For 32BCQD support. Does nothing by default. }
-
- PROCEDURE TOffscreen.Fields(PROCEDURE
- DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- END;
-
- TOldGrossOffscreen = OBJECT (TOffscreen)
-
- fBigBuff: Ptr; { The memory to use for our pixels in the
- offscreen world. You can get their
- address with GetOffPixBase. }
- fOffDevice: GDHandle; { Holds the offscreen device to use when
- playing with the offscreen world. You
- can fetch the device if you need to
- with GetOffDevice. }
- fOffPort: CGrafPtr; { Holds the offscreen GrafPort to use
- when playing with the offscreen world.
- You can fetch the port if you need to
- with GetOffPort. }
-
- PROCEDURE TOldGrossOffscreen.IOldGrossOffscreen(offBounds: Rect;
- itsColors: CTabHandle);
- { Create and initialize an offscreen drawing environment using the routines
- described in Inside Mac V. The offscreen world size is specified by
- “offBound”, and uses the colors in itsColors. It makes a copy of the
- table. }
-
- PROCEDURE TOldGrossOffscreen.Free; OVERRIDE;
-
- FUNCTION TOldGrossOffscreen.GetOffDevice: GDHandle; OVERRIDE;
- FUNCTION TOldGrossOffscreen.GetOffPixBase: Ptr; OVERRIDE;
- FUNCTION TOldGrossOffscreen.GetOffPort: CGrafPtr; OVERRIDE;
-
- PROCEDURE TOldGrossOffscreen.SetupOffWorld; OVERRIDE;
- { The default SetupOffWorld doesn’t do anything because it doesn’t know what
- form our offscreen management takes. So we have to override it here. }
-
- PROCEDURE TOldGrossOffscreen.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE
- ;
-
- END;
-
- TNewCoolOffscreen = OBJECT (TOffscreen)
-
- fOffWorld: GWorldPtr;
-
- PROCEDURE TNewCoolOffscreen.INewCoolOffscreen(offBounds: Rect;
- itsColors: CTabHandle);
- { Create and initialize an offscreen drawing environment using the 32-bit Color
- QuickDraw routines. The offscreen world size is specified by “offBound”, and
- uses the colors in itsColors. It makes a copy of the table. }
-
- PROCEDURE TNewCoolOffscreen.Free; OVERRIDE;
-
- FUNCTION TNewCoolOffscreen.GetOffDevice: GDHandle; OVERRIDE;
- FUNCTION TNewCoolOffscreen.GetOffPixBase: Ptr; OVERRIDE;
- FUNCTION TNewCoolOffscreen.GetOffPort: CGrafPtr; OVERRIDE;
-
- PROCEDURE TNewCoolOffscreen.LockThePixels; OVERRIDE;
-
- PROCEDURE TNewCoolOffscreen.PostDraw; OVERRIDE;
- { The base PostDraw will set the port and gDevice correctly. However, before it
- does that, we have to make sure that we unlock our offscreen bit so that the
- can float around and not fragment our heap. }
-
- PROCEDURE TNewCoolOffscreen.SetupOffWorld; OVERRIDE;
- { The default SetupOffWorld doesn’t do anything because it doesn’t know what
- form our offscreen management takes. So we have to override it here. }
-
- PROCEDURE TNewCoolOffscreen.UnlockThePixels; OVERRIDE;
-
- PROCEDURE TNewCoolOffscreen.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- END;
-
- IMPLEMENTATION
-
- {$I UOffscreen.inc1.p}
-
- END.
-